package com.tanhua.server.controller;

import com.tanhua.server.service.DeliverService;
import com.tanhua.server.vo.DeliverVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("peachblossom")
public class DeliverController {

    @Autowired
    private DeliverService deliverService;
    /**
     * 桃花传音-接收语音
     * @return
     */
    @GetMapping
    public ResponseEntity<DeliverVo> receive(){
        try {
            DeliverVo deliverVo=  deliverService.receive();
            return ResponseEntity.ok(deliverVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 桃花传音-发送语音
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> deliver(@RequestParam("soundFile") MultipartFile file){
        try {
            String id = deliverService.deliver(file);
            if (null != id){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
